using ASP;
using HoWave.Common;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Collections;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.WebControls;
public class Member_Shop_TeamBuy : Member, IRequiresSessionState
{
	private int UserID = 0;
	private string wherestr = "";
	private ArrayList al = new ArrayList();
	private IDbDataParameter[] param = null;
	private int type = 0;
	protected Literal TeamBuyTitle;
	protected DropDownList DropDownList1;
	protected TextBox TxtProductName;
	protected Button QuickSearch;
	protected GridView GridView1;
	protected PlaceHolder ListPanel;
	protected GridView GridView2;
	protected PlaceHolder RecordPanel;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.UserID = base.user.UserID;
		if (!base.IsPostBack)
		{
			if (Fetch.Get("action") == "record")
			{
				this.RecordPanel.Visible = true;
				this.ListPanel.Visible = false;
				this.BindRecord();
			}
			else
			{
				this.RecordPanel.Visible = false;
				this.ListPanel.Visible = true;
				this.BindList();
			}
		}
		this.GridView1.PageIndexChanging += new GridViewPageEventHandler(this.PageIndexChanging);
		this.GridView2.PageIndexChanging += new GridViewPageEventHandler(this.PageIndexChanging2);
	}
	protected void BindList()
	{
		this.QuestString();
		if (this.al.Count > 0)
		{
			this.param = new IDbDataParameter[this.al.Count];
			this.al.CopyTo(this.param, 0);
		}
		this.type = Convert.ToInt32(this.DropDownList1.SelectedValue);
		Shop_Product shop_Product = new Shop_Product(this.conn);
		string fields = "*,(Select sum(Quantity) From HLShop_OrderItem  Where HLShop_OrderItem.ProductID=HLShop_Product.ProductID) as Quantity ";
		if (this.param != null)
		{
			this.GridView1.DataSource = shop_Product.GetSalerTeamBuyProduct(this.UserID, this.type, fields, this.wherestr, this.param);
		}
		else
		{
			this.GridView1.DataSource = shop_Product.GetSalerTeamBuyProduct(this.UserID, this.type, fields, this.wherestr, null);
		}
		this.GridView1.DataBind();
	}
	public string GetProductOrderFormNum(string ProductID)
	{
		return this.conn.ExecuteCount("select count(a.OrderFormID) from HLShop_Order as a inner join HLShop_OrderItem as b on a.OrderFormID=b.OrderFormID where b.ProductID=" + int.Parse(ProductID)).ToString();
	}
	public string TeamCycleNum(string ProductID)
	{
		Shop_Product shop_Product = new Shop_Product(this.conn);
		return shop_Product.CountTeamCycleNum(int.Parse(ProductID));
	}
	protected void QuestString()
	{
		string text = Fetch.Get("productname");
		if (!string.IsNullOrEmpty(text))
		{
			this.TxtProductName.Text = text;
		}
		else
		{
			text = this.TxtProductName.Text;
		}
		if (text != string.Empty)
		{
			this.wherestr += "and ProductName like '%' + @ProductName + '%' ";
			this.al.Add(this.conn.CreateParameter("@ProductName", DbType.String, text.Trim()));
		}
		if (this.wherestr != string.Empty)
		{
			this.wherestr = "and" + this.wherestr;
			this.wherestr = this.wherestr.Replace("andand", "where");
		}
	}
	protected void BindRecord()
	{
		int iD = Fetch.GetID("productid");
		if (iD == 0)
		{
			this.WriteErrMsg("", Language.Get("Common/LostParam", "productid"), "");
		}
		Shop_Order shop_Order = new Shop_Order(this.conn);
		this.GridView2.DataSource = shop_Order.GetAllTeamOrderForm(this.UserID);
		this.GridView2.DataBind();
	}
	protected void QuickSearch_OnClick(object sender, EventArgs e)
	{
		this.BindList();
	}
	protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
	{
		this.GridView1.PageIndex = e.NewPageIndex;
		this.BindList();
	}
	protected void PageIndexChanging2(object sender, GridViewPageEventArgs e)
	{
		this.GridView2.PageIndex = e.NewPageIndex;
		this.BindRecord();
	}
	protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
	{
		if (e.Row.RowType == DataControlRowType.DataRow)
		{
			e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#E7EDFE'");
			e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c;");
		}
	}
	protected string GetStatus(int MoneyReceipt, string str)
	{
		int iD = Fetch.GetID("productid");
		decimal d = (decimal)this.conn.GetScalar("Select TempSubScriptionRate From [HLShop_Product] Where productid=" + iD, new IDbDataParameter[0]);
		string memberMsg;
		if (MoneyReceipt <= 0 && d > 0m)
		{
			memberMsg = Language.GetMemberMsg("Order/Auction/Status/Status3", new string[0]);
		}
		else
		{
			if (str == "1")
			{
				memberMsg = Language.GetMemberMsg("Order/TeamBuy/Status/Status1", new string[0]);
			}
			else
			{
				if (str == "2")
				{
					memberMsg = Language.GetMemberMsg("Order/TeamBuy/Status/Status2", new string[0]);
				}
				else
				{
					memberMsg = Language.GetMemberMsg("Order/TeamBuy/Status/Status0", new string[0]);
				}
			}
		}
		return memberMsg;
	}
}
